package com.cskaoyan.service.impl;

import com.cskaoyan.mapper.UserMapper;
import com.cskaoyan.model.User;
import com.cskaoyan.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @PROJECT_NAME: git_homework
 * @DESCRIPTION:
 * @Author: qiu
 * @DATE: 2021/10/16 22:21
 */
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    UserMapper userMapper;

    @Override
    public User login(User user) {

        if (user == null || user.getUsername() == null || user.getPassword() == null) {
            return null;
        }

        User res = userMapper.login(user);

        if (res.getId() != null) return res;

        return null;
    }

    @Override
    public void register(User user) {

        userMapper.register(user);
    }

    @Override
    public User selectByPrimaryKey(Integer id) {
        return userMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<User> getAllUser() {
        return userMapper.getAllUser();
    }

    @Override
    public List<User> getUserLikeUsername(String username) {

        return userMapper.getUserLikeUsername(username);
    }
}
